import { decode, encode } from "cbor-x";
import { serverFetch, serverFetch2 } from "./http"
import { ref } from "vue";

export interface TbDevice {
    id: number,
    name: string | null,
    language: string | null,
    location: string | null,
    mac_addr: string,
    ipc_version: string | null,
    phone_number: string | null,
    mcu_version: string | null,
    tick_timestamp: number,
}

export interface UpdateDeviceReq {
    name: string,
    language: string | null,
    location: string | null,
}

export default {

    async queryAll() {
        const resp = await serverFetch('/device/query_all', 'GET');
        return decode(resp.body) as TbDevice[];
    },

    async update(deviceId: number, req: UpdateDeviceReq) {
        await serverFetch2('/device/update_with_web', 'POST', deviceId, encode(req));
    },

    async delete(deviceId: number) {
        await serverFetch2('/device/delete', 'POST', deviceId);
    }
}






